﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using NHunspell;

namespace Modulo4
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Count() != 4)
            {
                Console.WriteLine("Args error!");
                return;
            }
            var dataEntreFileName = args[0];
            var dataOutputFileName = args[1];
            var logFileName = args[2];
            var errFileName = args[3];

            int entryRegisterCout = 0;
            int procesedResgisterCount = 0;
            int outputRegisterCount = 0;

            var outputFile = new StreamWriter(dataOutputFileName);
            var logFile = new StreamWriter(logFileName);
            var errFile = new StreamWriter(errFileName);
            
            logFile.WriteLine("==== Module #4====");
            logFile.WriteLine(DateTime.Now.ToString());
            errFile.WriteLine("==== Module #4====");
            errFile.WriteLine(DateTime.Now.ToString());

            const char Separator = '\n';
            var words = File.ReadAllText(dataEntreFileName, Encoding.UTF8).Split(new[] { Separator });
            foreach (var word in words)
            {
                var stringWord = new String(word.Where(Char.IsLetter).ToArray());
                if (word.Length == 0)
                {
                    continue;
                }
                entryRegisterCout++;

                bool isNoun = false;
                bool isVerb = false;
                string type = "";

                if( stringWord.Length > 2 )
                {
                    var lastChar = stringWord.ToCharArray().Last();
                    if(lastChar == 'r')
                    {
                        var c = stringWord.ToCharArray()[stringWord.Length - 2];
                        if( c == 'a' || c == 'e' || c == 'i' )
                        {
                            isVerb = true;
                        }else
                        {
                            isNoun = true;
                        }
                    }else
                    {
                        isNoun = true;
                    }
                }else
                {
                    isNoun = true;
                }

                if( isNoun )
                {
                    type = "NOUN";
                }
                if (isVerb)
                {
                    type = "VERB";
                }
                outputFile.WriteLine(type + ";" + stringWord);
                outputRegisterCount++;
                procesedResgisterCount++;
            }

            logFile.WriteLine("Input Register Count : " + entryRegisterCout);
            logFile.WriteLine("Procesed Register Count : " + procesedResgisterCount);
            logFile.WriteLine("Output Register Count : " + outputRegisterCount);
            logFile.WriteLine(DateTime.Now.ToString());
            errFile.WriteLine(DateTime.Now.ToString());

            outputFile.Flush();
            logFile.Flush();
            errFile.Flush();

            outputFile.Close();
            logFile.Close();
            errFile.Close();
        }
    }
}
